<template>
  <div class="app-container">
    <el-table :data="list" border fit highlight-current-row>
      <el-table-column align="center" label="菜品封面">
        <template v-slot="scope">
          <img :src="scope.row.cover" alt="cover" height="80" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="菜品ID">
        <template v-slot="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column align="center" label="菜品名称">
        <template v-slot="scope">{{ scope.row.title }}</template>
      </el-table-column>
      <el-table-column align="center" label="菜品描述">
        <template v-slot="scope">{{ scope.row.description }}</template>
      </el-table-column>
      <el-table-column align="center" label="菜品价格">
        <template v-slot="scope">{{ scope.row.price }}</template>
      </el-table-column>
      <el-table-column align="center" label="菜系ID">
        <template v-slot="scope">{{ scope.row.cuisineId }}</template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template v-slot="scope">
          <el-button type="primary" size="mini" @click="updateRow(scope.row)"
            >修改</el-button
          >
          <el-button type="danger" size="mini" @click="removeRow(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="js">
import { menuList, deleteMenu } from '@/api/api-v1/menu' 

export default {
  data() {
    return {
      list: []
    }
  },
  methods: {
    fetchData() {
      menuList().then(res => {
        this.list = res.data
      })
    },
    removeRow({id}){
      console.log(13);

      deleteMenu(id).then(()=>{
        this.$message.success("删除成功")
        this.fetchData()
      })
    },
    updateRow({ id }) {
      this.$router.push({
        path: "/menu/form",
        query: { id }
      })
    }
  },
  created() {
    this.fetchData()
  }
}
</script>

<style></style>
